// 日志级别共4级
// infoLog:    "INFO" = 0
// warningLog: "WARNING" = 1
// errorLog:   "ERROR" = 2
// fatalLog:   "FATAL" = 3

// 日志格式 Lyyyy-mm-dd hh:mm:ss.uuuuuu threadid file:line]
// L 表示日志等级, 分别为I，W，E，F, 即：INFO, WARNING, ERROR, FATAL
// yyyy-mm-dd hh:mm:ss.uuuuuu 为时间格式，年月日，时分秒毫秒
// threadid 表示线程ID
// file:line 表示那个文件的第几行打印
// ] 后面为具体打印的信息
package gluelog

import "gluenet/internal/glue-srvm/pkg/klog"

const TranceIdKey = "tranceId"

type InfoLogger interface {
	Info(args ...interface{})
	Infoln(args ...interface{})
	Infof(format string, args ...interface{})
}

type WarningLogger interface {
	Warning(args ...interface{})
	Warningln(args ...interface{})
	Warningf(format string, args ...interface{})
}

type ErrorLogger interface {
	Error(args ...interface{})
	Errorln(args ...interface{})
	Errorf(format string, args ...interface{})
}

type FatalLogger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(v ...interface{})
}

var _logger logger

type logger struct {
	klog.LoggingT
}

func Logger() *logger {
	return &_logger
}

func init() {
	_logger.StderrThreshold = klog.ErrorLog // Default stderrThreshold is ERROR.
	_logger.SetVState(0, nil, false)
	_logger.LogDir = ""
	_logger.LogFile = ""
	_logger.LogFileMaxSizeMB = 1800
	_logger.ToStderr = true
	_logger.AlsoToStderr = false
	_logger.SkipHeaders = false
	_logger.AddDirHeader = true
	_logger.SkipLogHeaders = false
	go _logger.FlushDaemon()
}

func (l *logger) Info(args ...interface{}) {
	l.LoggingT.Print(klog.InfoLog, args...)
}

func (l *logger) Infoln(args ...interface{}) {
	l.LoggingT.Println(klog.InfoLog, args...)
}

func (l *logger) Infof(format string, args ...interface{}) {
	l.LoggingT.Printf(klog.InfoLog, format, args...)
}

func (l *logger) Warning(args ...interface{}) {
	l.LoggingT.Print(klog.WarningLog, args...)
}

func (l *logger) Warningln(args ...interface{}) {
	l.LoggingT.Println(klog.WarningLog, args...)
}

func (l *logger) Warningf(format string, args ...interface{}) {
	l.LoggingT.Printf(klog.WarningLog, format, args...)
}

func (l *logger) Error(args ...interface{}) {
	l.LoggingT.Print(klog.ErrorLog, args...)
}
func (l *logger) Errorln(args ...interface{}) {
	l.LoggingT.Println(klog.ErrorLog, args...)
}
func (l *logger) Errorf(format string, args ...interface{}) {
	l.LoggingT.Printf(klog.ErrorLog, format, args...)
}

func (l *logger) Fatal(args ...interface{}) {
	l.LoggingT.Print(klog.FatalLog, args...)
}
func (l *logger) Fatalln(args ...interface{}) {
	l.LoggingT.Println(klog.FatalLog, args...)
}
func (l *logger) Fatalf(format string, args ...interface{}) {
	l.LoggingT.Printf(klog.FatalLog, format, args...)
}

func (l *logger) Print(v ...interface{}) {
	l.LoggingT.Print(klog.InfoLog, v...)
}

func Info(args ...interface{}) {
	_logger.LoggingT.Print(klog.InfoLog, args...)
}

func Infoln(args ...interface{}) {
	_logger.LoggingT.Println(klog.InfoLog, args...)
}

func Infof(format string, args ...interface{}) {
	_logger.LoggingT.Printf(klog.InfoLog, format, args...)
}

func Warning(args ...interface{}) {
	_logger.LoggingT.Print(klog.WarningLog, args...)
}

func Warningln(args ...interface{}) {
	_logger.LoggingT.Println(klog.WarningLog, args...)
}

func Warningf(format string, args ...interface{}) {
	_logger.LoggingT.Printf(klog.WarningLog, format, args...)
}

func Error(args ...interface{}) {
	_logger.LoggingT.Print(klog.ErrorLog, args...)
}
func Errorln(args ...interface{}) {
	_logger.LoggingT.Println(klog.ErrorLog, args...)
}
func Errorf(format string, args ...interface{}) {
	_logger.LoggingT.Printf(klog.ErrorLog, format, args...)
}

func Fatal(args ...interface{}) {
	_logger.LoggingT.Print(klog.FatalLog, args...)
}
func Fatalln(args ...interface{}) {
	_logger.LoggingT.Println(klog.FatalLog, args...)
}
func Fatalf(format string, args ...interface{}) {
	_logger.LoggingT.Printf(klog.FatalLog, format, args...)
}
